<template>
  <div>
    <a-select :style="{ width: newItem.keyWidth + 'px' }" placeholder="请选择" v-model="newItem.key" @change="selTitle">
      <a-option v-for="item of newItem.keyItems" :key="item.value" :label="item.label" :value="item.value" />
    </a-select>
    <a-range-picker v-model="newItem.value" shortcuts-position="left" :shortcuts="rangeShortcuts(newItem.attrs ? newItem.attrs.valueFormat : 'YYYY-MM-DD')" :style="{ width: newItem.width + 'px' }" :="newItem.attrs" @change="getSearch" />
  </div>
</template>

<script lang="ts">
  import { toRefs } from '@vueuse/core'
  import { defineComponent, reactive, computed } from 'vue'
  import { rangeShortcuts } from '@/utils/timeFormat'
  export default defineComponent({
    props: ['data'],
    emits: [],
    setup(props, { emit }) {
      const data = reactive({
        time: [],
      })
      const newItem: any = computed({
        set(val) {
          emit('update:data', val)
        },
        get() {
          return props.data
        },
      })
      const selTitle = (val: any) => {
        let obj = newItem.value.keyItems.find((e: any) => e.value == val)
        newItem.value.label = obj.label
        getSearch()
      }

      const getSearch = () => {
        emit('search')
      }

      return {
        ...(toRefs(data) as any),
        newItem,
        selTitle,
        getSearch,
        rangeShortcuts,
      }
    },
  })
</script>

<style lang="less" scoped></style>
